﻿using System.Collections.Generic;

namespace SmallDataBase.DTO
{
    /// <summary>
    /// 被拆解后的元对象
    /// </summary>
    public class MetaDTO
    {
        /// <summary>
        /// 主键集合
        /// </summary>
        public IEnumerable<FieldDTO> PrimaryKey { get; set; }

        /// <summary>
        /// 自增主键
        /// </summary>
        public FieldDTO AutoIncrement { get; set; }

        /// <summary>
        /// 字段集合
        /// </summary>
        public IEnumerable<FieldDTO> Columns { get; set; }

        /// <summary>
        /// 表名称
        /// </summary>
        public string TableName { get; set; }

        /// <summary>
        /// 数据库名称
        /// </summary>
        public string DataBaseName { get; set; }

        /// <summary>
        /// 根据配置获取列集合
        /// </summary>
        /// <param name="needColumns">是否需要普通列</param>
        /// <param name="needPK">是否需要主键</param>
        /// <param name="needAuto">是否需要自增列</param>
        /// <returns>需要列集合</returns>
        public IEnumerable<FieldDTO> GetFields(bool needColumns, bool needPK, bool needAuto)
        {
            var list = new List<FieldDTO>();
            if (needColumns)
            {
                list.AddRange(Columns);
            }
            if (needPK)
            {
                list.AddRange(PrimaryKey);
            }
            if (needAuto && null != AutoIncrement)
            {
                list.Add(AutoIncrement);
            }
            return list;
        }
    }
}